using System;
using System.Reflection;
using NUnit.Framework;
using ValidationFramework;

namespace ExampleLibraryCSharp.ParameterValidationManagerExamples
{
	public class ExplicitHandleExample
	{
		#region Example
		public interface IPerson
		{
			void CheckAge(int age);
		}

		public class Person : IPerson
		{
			private const string methodName = "ExampleLibraryCSharp.ParameterValidationManagerExamples.ExplicitHandleExample.IPerson.CheckAge";
			private static readonly RuntimeMethodHandle checkAgeHandle =
				typeof(Person).GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Instance).MethodHandle;
            
			void IPerson.CheckAge(
				[CompareIntRule(5, CompareOperator.LessThan)] int age)
			{
				ParameterValidationManager.ThrowException(this, checkAgeHandle, age);
				//business code goes here.
			}
		}


		[TestFixture]
		public class ExampleUsage
		{
			[Test]
			[ExpectedException(typeof(ArgumentException))]
			public void RunInvalidData()
			{
                IPerson person = new Person();
				person.CheckAge(7);
			}


			[Test]
			public void RunValidData()
			{
                IPerson person = new Person();
				person.CheckAge(2);
			}
		}
		#endregion
	}
}